
<div class="container score-banner">
    <div class="col-md-12">
        <div class="pull-left score-top-banner">
        	<ul>
        		<li><img src="<?php echo Yii::app()->theme->baseUrl; ?>/assets/images/score_banner.jpg" alt="积分兑换banner"/></li>
        		<li><img src="<?php echo Yii::app()->theme->baseUrl; ?>/assets/images/score_banner_2.jpg" alt="积分兑换banner"/></li>
            </ul>
        </div>
        <div class="pull-right info-col">

            <div class="con_waiter jf-qq-col">
                <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=1607188278&site=qq&menu=yes" class="qq pull-right" rel="nofollow">
                    <img src="<?php echo Yii::app()->theme->baseUrl; ?>/assets/images/qq-socre.gif">
                    <div class="suport pink">客服</div>
                </a>
                <div class="suport bolder pink" style="font-size:18px;"><img class="step_instruct" src="<?php echo Yii::app()->theme->baseUrl; ?>/assets/images/score/step_instructions.png">积分公告</div>
                <div class="clearfix"></div>
            </div>

            <div class="pull-1 con_waiter" style="height:103px;">
                <ul style="">
                    <li><a href="/article/10" target="_blank" class="pink">· 买家积分兑换详细流程</a></li>
                    <li>· 卖家QQ群: 398812697</li>
                    <li>· 买家QQ群: 298938571</li>
                </ul>
            </div>

            <div class="wb-cols">
                <div class="wb-cols-b full_left left_width">
                    <div class='wb-cols-c'>我的积分<br/>
                        <font style="color:#CE6181;font-size:13px"><?php
                        if (Yii::app()->user->isLogged()) {
                            echo Yii::app()->user->score;
                        } else {
                            echo '0';
                        }
                        ?></font>
                    </div>    
                </div>
                <div class="wb-cols-b full_right right_width">
					<a style="line-height:40px;" href="http://bbs.1zw.com">1折网论坛</a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="wb-cols">
                <div  class="full_left left_width" style="border-radius:4px;"><a target="_blank" href="<?php echo yii::app()->createUrl('/front/article/show', array('id' => 12)) ?>">积分规则</a></div>
                <div class="full_right right_width" style="border-radius:4px;">
                    <a rel="nofollow" href="http://g.click.taobao.com/q?pid=mm_34837309_4174087_14402594&rd=2&ct=url%3Dhttp%253A%252F%252Fbangpai.taobao.com%252Fgroup%252F14631514.htm&rf=http%3A%2F%2Fyii.1zw.com%2F&et=90949100&pgid=c09fbe6e103ec136e719b443c58718d1&v=1.1">1折网帮派</a>
                </div>
                <div class="clearfix"></div>
            </div>
            <!--            
                        <div class='con_last'>
                            <div class="wb-lastleft"><a href="/article/12.html">积分规则</a></div>
                            <div class="wb-lastright"><a href="/article/6.html">帮助中心</a></div>
                            <div class="clearfix"></div>
                        </div>
            -->

            <div class="clearfix"></div>
        </div>
    </div>
    <div class="clearfix"></div>
</div>
<div class="container score-col">
    <?php
    foreach ($data as $rs) {
        ?>

        <?php
        $sum = $rs->RecordQuantum;
        ?>

        <div class="col-3 <?php
        if ($rs->quantum - $sum <= 0) {
            echo "sell-over";
        }
        ?>"  >
            <div class="thumbnail" id="<?php echo $rs->id; ?>">
                <a target="_blank" href="<?php echo yii::app()->createUrl('/front/good/redeemskip', array('gid' => $rs->id)) ?>"> 
                    <img class="lazy good_img" src="/images/1zw.gif" data-original="<?php echo $rs->thumb ?>" alt=""  >                  
                    <?php
                    $res = $rs->quantum - $sum;
                    if ($res > 0) {
                        echo '<span class="wb-good wb-good-font">还剩<am class="number">' . $res . '</am>件</span>';
                    }
                    ?> 
                </a>
                <div style="position:relative" class="caption">
                    <div class="score_title">
                        <div class="good_desc"><?php echo $rs->title ?></div>
                        <div class="good_num">
                            限量<span class="black"> <?php echo $rs->quantum; ?> </span>件
                            <!--
                            <?php if ($rs->quantum - $sum > 0) { ?>
                                                                    限量<span class="black"> <?php echo $rs->quantum; ?> </span>件
                            <?php } else { ?>
                                                                    <span  class="red">已兑换完</span>
    <?php } ?>
                            -->
                        </div>

                    </div>


                    <div class="sales-col"> 
                        <div class="pull-left score">
                            <span><?php echo $rs->integral ?></span>积分
                        </div>

                        <div class="pull-right price font-arial score_value">
                            价值: <font class='font_set'>&yen;<?php echo $rs->worth ?></font>
                        </div>

                    </div>
                    <div class="dotted">
                        <?php
                        //echo "@@".$rs->scoregood_intervals;
                        if ($sum >= $rs->quantum):
                            ?>
                            <div style="background-color:#dadada" class="pull-right btn" >
                                已兑完
                            </div>
                            <?php
                        else:
                            ?>

                            <!-- 开始兑换时间 -->
                            <?php if($rs->exchange_start_time >= $time){ ?>
                            <?php 
                                //明日还是今日
                                $exchange_start_time = date('H:i', $rs->exchange_start_time);
                                if($rs->exchange_start_time >= strtotime('tomorrow')){
                                    $timehtml = "明日{$exchange_start_time}开抢";
                                }else{
                                    $timehtml = "{$exchange_start_time}开抢";
                                }
                             ?>
                                <div class="pull-right btn" style="background-color:#339e14">
                                    <?php echo $timehtml; ?>
                                </div>                            
                            <?php }else{ ?> 
                                <div class="pull-right  convert " data-url="<?php echo yii::app()->createUrl('/front/good/redeemskip', array('gid' => $rs->id)) ?>" data-id="<?php echo $rs->id ?>" data-title="<?php echo $rs->title ?>" data-integral="<?php echo $rs->integral ?>">
                                    立即兑换
                                </div>
                            <?php } ?> 


                        <?php
                        endif;
                        ?>
                    </div><?php if (empty($rs->introduction)): ?>
                        <div>                           
                        </div>                   
                        <?php
                    else:
                        ?>
                        <div class="introduct_jifen">
                            产品描述：<?php echo $rs->introduction ?>
                        </div>
                    <?php
                    endif;
                    ?>

                </div>
            </div>
            <a class="no_stock_icon" title="<?php echo $rs->title ?>" _hover-ignore="1" _orighref="" _tkworked="true"></a>
        </div>
    <?php } ?>
    <div class="clearfix"></div>
<?php include $this->getViewFile('//user/lib/login_and_reg'); ?>
</div>
<div id="tangchuang" style="display:none" class="success_convert">
    <div id="content" class="success_content">
        <div class="img"></div>
        <div class="success_text">
            <p class="black bolder title">恭喜您，兑换成功。</p>
            <p class="row">请完善及确认收货地址，以便宝贝尽快寄出。</p>
        </div>
        <div class="clear"></div>
    </div>
    <div class="share-box">
        <div class="share">
            <div style="color:#000;padding:10px 0 10px 76px" class="title pull-left">分享送积分：</div>
            <div id="share" style="padding:6px 0" class="bdsharebuttonbox pull-left" data-tag="share_2" data-text="sh2" id="share_2">
                <a class="bds_weixin" data-cmd="weixin"></a>
                <a class="bds_sqq" data-cmd="sqq"></a>
                <a class="bds_tsina" data-cmd="tsina"></a>
                <a class="bds_qzone" data-cmd="qzone" href="#"></a>       
                <a class="bds_more" data-cmd="more"></a>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>



<script src="<?php echo Yii::app()->params->staticUrl; ?>statics/js/ajaxForm.js"></script> 
<link rel="stylesheet" href="<?php echo Yii::app()->params->staticUrl; ?>statics/js/artDialog6/css/ui-dialog.css">
<script src="<?php echo Yii::app()->params->staticUrl; ?>statics/js/artDialog6/js/dialog-min.js"></script> 

<script>
var pagetype = 'jifen';

$(document).ready(function() {
	$(".score-banner").slide({mainCell:".score-top-banner ul",effect:"leftLoop",autoPlay:true,delayTime:500,interTime:5000});
   	$(".thumbnail").mouseover(function() {
        var id = this.id;
        if(id !== ''){
        	$('#record_product_id').val(id);
            $('#' + id + ' .introduct_jifen').css('display', 'block');           
        }
    });
    $(".thumbnail").mouseout(function() {
        var id = this.id;
        if(id !==''){
        	$('#' + id + ' .introduct_jifen').css('display', 'none');               
        }
    });
     });

    var share_jifen = true;	//是否显示右侧浮动层
    $(document).ready(function() {
        var d = dialog({
            content:
                    "<div class='score_begin_div'>" +
                    "<div class='wrap'>" +
                    "<a id='score_close' class='score_close' href='javascript:void(0);' ></a>" +
                    "<a class='score_step' href='<?php echo yii::app()->createUrl('/front/article/show', array('id' => 10)) ?>' target='_blank'></a>" +
                    "<a class='score_rule' href='<?php echo yii::app()->createUrl('/front/article/show', array('id' => 12)) ?>' target='_blank'></a>" +
                    "</div>" +
                    "</div>",
            padding: 0,
            quickClose: true
        });
<?php if ($result) echo "d.show();"; ?>


        $('#score_close').click(function() {
            $('.score_begin_div').hide();
        });
    });

    var userid = '<?php echo (int) Yii::app()->user->id ?>';
    var userkind = '<?php echo (int) Yii::app()->user->kind ?>';
    var username = '<?php echo $user->username ?>';
    var lock = false;
    var tangchuang = $("#tangchuang");
//登录
    function login(obj) {
        $('div.login_reg_page').show();
        $("#login-regmobile").append('<input  type="hidden" value="1" name="MembersModel[kind]" />');
        $('#login-form').ajaxForm({
            dataType: 'json',
            url: '<?php echo YzwController::U('user/bm/login') ?>',
            success: function(data) {
                if (data.status) {
                    $('#login-form').clearForm();
                    $('div.login_reg_page').hide();
                    userid = true;
                    userkind = data.kind;
                    if (parseInt(userkind) == 0) {
                        var d = dialog({
                            title: '提示',
                            content: '亲，您的账户类型是“商家用户”，不能进行积分商品兑换！',
                            cancel: false,
                            okValue: '确定',
                            ok: function() {
                            }
                        });
                        d.show();
                        return true;
                    }
                    exchange(obj);
                    //$('#goodsbm').submit();
                } else {
                    var d = dialog({
                        title: '提示',
                        content: data.info,
                        cancel: false,
                        okValue: '确定',
                        ok: function() {
                        }
                    });
                    d.show();
                }
            }
        });
        $('#login-regmobile').ajaxForm({
            dataType: 'json',
            success: function(data) {
                if (data.status) {
                    $('#login-form').clearForm();
                    $('div.login_reg_page').hide();
                    //$('#goodsbm').submit();
                } else {
                    var d = dialog({
                        title: '提示',
                        content: data.info,
                        cancel: false,
                        okValue: '确定',
                        ok: function() {
                        }
                    });
                    d.show();
                }
            }
        });
    }


    function exchange(obj) {
        lock = true;
        var olt = obj.html();
        obj.html('兑换中...');
        $.getJSON('<?php echo IndexController::U('user/redeemrecord/exchange') ?>', {id: obj.data('id')}, function(data) {
            if (data.status) {
                //$("#content").html(data.info);
                //$("#share").after('<div style="padding:10px 80px 0 70px;float:left"><a href="' + obj.data("url") + '">去购买</a></div>');
                tips = dialog({
                    title: '提示',
                    okValue: '下一步',
                    ok: function() {
                        //var url = $('#ok_url').attr('href');
                        //window.open(obj.data("url"));
                        //NODE
                        window.location.href = "<?php echo yii::app()->createUrl('/user/info/address') ?>";
                        return true;
                    },
                    content: tangchuang.show()
                }).show();
                var ob = obj.parents('.thumbnail').find('a > span.wb-good-font > .number').eq(0);
                var len = ob.html() - 1;
                ob.html(len);
                if (len <= 0) {
                    obj.removeClass('convert');
                    $('.wb-good').hide();
                    obj.attr({
                        style: 'background-color:#C2C2C2',
                    });
                    //obj.parents('.thumbnail').find('.pull-right').eq(0).html('<span class="red">已兑换完</span>');
                }
            } else {
                if (data.info == 'not_logged')
                {
                    lock = false;
                    login();
                    return true;
                }
                //alert(data.info);
                tips = dialog({
                    title: '提示',
                    content: data.info,
                    okValue: '确定',
                    ok: function() {
                        return true;
                    },
                }).show();

                if (data.url) {
                    window.location.href = data.url;
                }
            }
            lock = false;
            obj.html(olt);
        });
    }

    $(function() {
        $(document).on('click', '.convert', function() {
            var obj = this;
            //OBJ = this;

            if (lock) {
                //alert('操作过快！');
                tips = dialog({
                    title: '提示',
                    content: '操作过快！',
                    okValue: '确定',
                    ok: function() {
                        return true;
                    },
                }).show();
                return false;
            }

            if (parseInt(userid) && !parseInt(userkind)) {
                var d = dialog({
                    title: '提示',
                    content: '亲，您的账户类型是“商家用户”，不能进行积分商品兑换！',
                    cancel: false,
                    okValue: '确定',
                    ok: function() {
                    }
                });
                d.show();
                return true;
            }
            tips = dialog({
                title: '友情提示',
                content: '您是否确定兑换该商品？<br/><br/><strong style="color:rgb(138, 138, 138);font-size:12px">确定后,将扣除积分,积分不退还</strong>',
                okValue: '确定',
                width:300,
                //height:100,
                ok: function() {
                    if (userid < 1) {
                        login($(obj));
                        return true;
                    }
                    exchange($(obj));
                    return true;
                },
                cancelValue: '取消',
                cancel: function() {
                    return true;
                },
            }).showModal();


        });
    });
</script>

<!-- 倒计时 -->
<script type="text/javascript">

</script>